package com.kmzx.one.project.others.dto;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.security.AnyTypePermission;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;

@XStreamAlias("xml")
@Getter
@Setter
@Accessors(chain = true)
@ToString
public class WikiPayResponse {


    @XStreamAlias("return_code")
    private String return_code;
    @XStreamAlias("return_msg")
    private String return_msg;
    @XStreamAlias("appid")
    private String appid;
    @XStreamAlias("mch_id")
    private String mch_id;
    @XStreamAlias("device_info")
    private String device_info;
    @XStreamAlias("nonce_str")
    private String nonce_str;
    @XStreamAlias("sign")
    private String sign;
    @XStreamAlias("result_code")
    private String result_code;
    @XStreamAlias("err_code")
    private String err_code;
    @XStreamAlias("err_code_des")
    private String err_code_des;
    @XStreamAlias("trade_type")
    private String trade_type;
    @XStreamAlias("prepay_id")
    private String prepay_id;
    @XStreamAlias("mweb_url")
    private String mweb_url;


    public String toXML() {
        XStream xstream = XStreamInitializer.getInstance();
        xstream.processAnnotations(this.getClass());
        return xstream.toXML(this);
    }


    public static WikiPayResponse fromXML(String xmlString) {
        XStream xstream = new XStream(new DomDriver("utf-8"));
        xstream.addPermission(AnyTypePermission.ANY);
        xstream.processAnnotations(WikiPayResponse.class);
        WikiPayResponse result = (WikiPayResponse) xstream.fromXML(xmlString);
        return result;
    }
}
